<template>
  <div class="user_wrap">
    <BreadCrumb crumb="sku管理"></BreadCrumb>
    <div class="top_bar">
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入搜索内容"
            v-model="keyword"
            class="input-with-select"
            size="small"
          >
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="fnGetData(1)"
            ></el-button>
          </el-input>
        </el-col>

        <el-col :span="8" :offset="8"
          ><AddSku @fnResetTable='fnGetData(1)' class="pull-right"></AddSku
        ></el-col>
      </el-row>
    </div>
    <SkuTable :skus="aSkuList" @fnResetTable="fnGetData(1)"></SkuTable>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :current-page="page"
      :page-size="pagesize"
      style="text-align: center; margin-top: 10px"
      @current-change="fnGetPage"
    >
    </el-pagination>
  </div>
</template>

<script>
import BreadCrumb from "@/components/widget/BreadCrumb";
import AddSku from "@/components/widget/AddSku";
import SkuTable from "@/components/widget/SkuTable";
import cons from "@/components/constant";

export default {
  name: "Sku",
  data() {
    return {
      keyword: "",
      page: 1,
      pagesize: 3,
      aSkuList: [],
      total: 0,
      pop_show: false,
    };
  },
  components: {
    BreadCrumb,
    AddSku,
    SkuTable,
  },
  // 当前组件刚刚完成挂载 就开始执行
  mounted() {
    this.fnGetData(1);
  },
  methods: {
    // 获取所有sku的数据
    fnGetData(num) {
      this.axios
        .get(cons.apis + "/v1/goods/skus/", {
          params: {
            page: this.num,
            pageSize: this.pagesize,
          },
          headers: {
            Authorization: "JWT " + localStorage.token,
          },
          ResponseType: "json",
        })
        .then((res) => {
          console.log("加载sku的响应", res);
          if (res.status == 200) {
            this.aSkuList = res.data;
          } else {
            this.$message({
              type: "error",
              message: "加载sku失败",
            });
          }
        })
        .catch((err) => {
          console.log("请求错误", err);
        });
    },
    // 切换分页时触发的方法
  },
};
</script>

<style scoped>
.top_bar {
  width: 95.2%;
  overflow: hidden;
  margin: 10px auto 10px;
}
</style>
